package cn.jwm.base.service.impl;

import cn.jwm.base.mapper.BaseMapper;
import cn.jwm.base.query.BaseQuery;
import cn.jwm.base.service.IBaseService;
import cn.jwm.utils.PageList;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Administrator
 */
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImp<T> implements IBaseService<T> {
    @Resource
    private BaseMapper baseMapper;

    @Transactional
    @Override
    public void add(T t) {
        baseMapper.add(t);
    }
    @Transactional
    @Override
    public void upData(T t) {
        baseMapper.upData(t);
    }

    @Override
    public T getById(Long id) {
        return getById(id);
    }

    @Override
    public List<T> getAll() {
        return getAll();
    }
    @Transactional
    @Override
    public void delete(Long id) {
        baseMapper.delete(id);
    }

    @Override
    public PageList<T> page(BaseQuery query) {
        long total = baseMapper.queryTotal(query);
        if (total>0){
            List<T> rows = baseMapper.queryData(query);
            return new PageList<>(total,rows);
        }
        return new PageList<>();
    }
    @Transactional
    @Override
    public void patchDelete(List<Long> ids) {

    }
}
